import {Map, List} from 'immutable';
import * as OrderConstant from '../constants/OrderConstant';

const initState = Map({
  apiRes: {},
  orderItems: [],
});

export default function Order(state = initState, action) {
  switch (action.type) {
    case OrderConstant.REQUEST_ORDER_ITEMS:
      let pageNo = action.pageNo;
      if (pageNo == 1) {
        state = state.set('orderItems', action.data.datas.list);  
      } else {
        let oldItems = state.get('orderItems');
        if (action.data.datas && action.data.datas.list) {
          oldItems = oldItems.concat(action.data.datas.list);
        }
        state = state.set('orderItems', oldItems);
      }
      state = state.set('apiRes', action.data);

      return state;
  }
  return state;
}